package org.csu.softwaremetrics_demo.entity.common;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: TraditionMetricSingleClass类用于存储单个类的Tradition度量指标。
 * @Author: Jukomu
 * @Package: org.csu.softwaremetrics_demo.entity.common
 * @Project: SoftwareMetrics_demo
 * @name: TraditionMetricSingleClass
 * @Date: 2025/4/6-20:14
 * @Filename: TraditionMetricSingleClass
 */
public class TraditionMetricSingleClass {
    // 文件路径
    private String file;
    // 类名
    private String className;
    // 类型
    private String type;

    // 代码行数
    private int loc;
    private int cc; // 类的圈复杂度
    private Map<String, Integer> ccMethod; // 类的方法的复杂度
    private int lineCommentLines;    // 单行注释行数
    private int blockCommentLines;   // 块注释行数
    private int javadocLines;       // Javadoc 注释行数
    private int lenOfComment;
    private double cp;

    private final Map<String, Integer> specific;
    private boolean error;

    public TraditionMetricSingleClass(String file, String className, String type) {
        this.file = file;
        this.className = className;
        this.type = type;

        this.specific = new HashMap<>();
    }

    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        String[] pathList = file.split("\\\\");
        map.put("file", pathList[pathList.length - 1]);
        map.put("class", className);
        map.put("type", type);
        map.put("loc", loc);
        map.put("cc", cc);
        map.put("ccMethod", ccMethod);
        map.put("lineCommentLines", lineCommentLines);
        map.put("blockCommentLines", blockCommentLines);
        map.put("javadocLines", javadocLines);
        map.put("lenOfComment", lenOfComment);
        map.put("cp", cp);
        map.put("specific", specific);
        map.put("error", error);

        return map;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((file == null) ? 0 : file.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        TraditionMetricSingleClass other = (TraditionMetricSingleClass) obj;
        if (file == null) {
            return other.file == null;
        } else {
            return file.equals(other.file);
        }
    }

    @Override
    public String toString() {
        return "LKMetricSingleClass [file=" + file + ", className=" + className + ", type="
                + type + ", loc=" + loc + ", cc=" + cc + ", ccMethod=" + ccMethod + ", lineCommentLines=" + lineCommentLines + ", blockCommentLines=" + blockCommentLines + ", javadocLines=" + javadocLines
                + ", lenOfComment=" + lenOfComment + ", cp=" + cp + " , specific=" + specific + ", error=" + error + "]";
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Map<String, Integer> getSpecific() {
        return specific;
    }

    public boolean isError() {
        return error;
    }

    public void setError(boolean error) {
        this.error = error;
    }

    public int getLoc() {
        return loc;
    }

    public void setLoc(int loc) {
        this.loc = loc;
    }

    public int getCc() {
        return cc;
    }

    public void setCc(int cc) {
        this.cc = cc;
    }

    public double getCp() {
        return cp;
    }

    public void setCp(double cp) {
        this.cp = cp;
    }

    public Map<String, Integer> getCcMethod() {
        return ccMethod;
    }

    public void setCcMethod(Map<String, Integer> ccMethod) {
        this.ccMethod = ccMethod;
    }

    public int getLenOfComment() {
        return lenOfComment;
    }

    public void setLenOfComment(int lenOfComment) {
        this.lenOfComment = lenOfComment;
    }

    public int getLineCommentLines() {
        return lineCommentLines;
    }

    public void setLineCommentLines(int lineCommentLines) {
        this.lineCommentLines = lineCommentLines;
    }

    public int getBlockCommentLines() {
        return blockCommentLines;
    }

    public void setBlockCommentLines(int blockCommentLines) {
        this.blockCommentLines = blockCommentLines;
    }

    public int getJavadocLines() {
        return javadocLines;
    }

    public void setJavadocLines(int javadocLines) {
        this.javadocLines = javadocLines;
    }
}
